package com.molyfun.parents.fragment.dialog;

import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.TextView;

import com.molyfun.parents.R;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class CheckinSuccessDialogFragment extends DialogFragment implements View.OnClickListener{

    @InjectView(R.id.integral_count)
    TextView mIntegralCount;
    @InjectView(R.id.checkin_close)
    View mCheckinClose;

    private static CheckinSuccessDialogFragment newInstance(int integral) {
        CheckinSuccessDialogFragment mStudentMenuDialogFragment = new CheckinSuccessDialogFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("integral", integral);
        mStudentMenuDialogFragment.setArguments(bundle);
        return mStudentMenuDialogFragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NORMAL, R.style.BaseDialog);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
        View view = inflater.inflate(R.layout.dialog_checkin_succ, container, false);
        ButterKnife.inject(this, view);
        int integral = getArguments().getInt("integral");


        mIntegralCount.setText(integral + "积分");
        mCheckinClose.setOnClickListener(this);
        return view;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.checkin_close:
                getDialog().dismiss();
                break;
            default:
                getDialog().dismiss();
                break;
        }

    }

    public static class CheckinSuccessDialogDialogBuilder {

        CheckinSuccessDialogFragment mCheckinSuccessDialogFragment;
        private String mTag;

        public CheckinSuccessDialogDialogBuilder(int integral){
            mCheckinSuccessDialogFragment = CheckinSuccessDialogFragment.newInstance(integral);
            mTag = "checkin_success";
        }

        public CheckinSuccessDialogDialogBuilder setTag(String tag){
            this.mTag = tag;
            return this;
        }

        public void build(FragmentTransaction fragmentTransaction){
//            mCommonDialogFragment.show(fragmentTransaction, mTag);
            fragmentTransaction.add(mCheckinSuccessDialogFragment, mTag);
            fragmentTransaction.commitAllowingStateLoss();
        }

    }
}
